﻿using B.S.DataBase.MyProject.Domain.wdx;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure;
using MediatR;
using MedicalPCTerminal.Write.API.Appcation.Commands.Sign;

namespace MedicalPCTerminal.Write.API.Appcation.CommandHandlers.Sign
{
    public class DelSignDeviceBindCommandHandler:IRequestHandler<DelSignDeviceBindCommand, APIResult<int>>
    {
        private readonly SqlSugarContext sqlSugar;

        public DelSignDeviceBindCommandHandler(SqlSugarContext sqlSugar)
        {
            this.sqlSugar = sqlSugar;
        }

        public Task<APIResult<int>> Handle(DelSignDeviceBindCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            var res = sqlSugar.db.Deleteable<SignDeviceBind>().Where(it => it.Id == request.Id).ExecuteCommand();
            if (res > 0)
            {
                result.data = res;
                result.Code = APIEnum.删除成功;
                result.Msg = APIEnum.删除成功.ToString();
            }
            else
            {
                result.data = 0;
                result.Code = APIEnum.删除失败;
                result.Msg = APIEnum.删除失败.ToString();
            }
            return Task.FromResult(result);
        }
    }
}
